<?php

namespace App\SubApps\Account\Controllers;

use App\SubApps\Account\Entities\OauthAppsLoginLogEntity;
use Hilaoyu\LaravelExtend\ControllerBaseResource;
use Hilaoyu\Utils\UtilHtml;
use Hilaoyu\Utils\UtilSupport;
use Illuminate\Http\Request;


class OauthAppsLoginLogController extends ControllerBaseResource
{

    protected function entity()
    {
        return new OauthAppsLoginLogEntity();
    }

     protected function alterModelsQuery($query,Request $request)
    {
        $query = parent::alterModelsQuery($query,$request);

        $search = [
            'oauth_app_name' => $request->input('oauth_app_name',''),
            'user_name' => $request->input('user_name',''),
        ];


        if(!empty($search['oauth_app_name'])){
            $query = $query->whereHas('oauth_app',function ($q) use ($search){
                return $q->Where('name','like','%'. $search['oauth_app_name'] .'%')
                    ;
            });
        }
        if(!empty($search['user_name'])){
            $query = $query->whereHas('login_user',function ($q) use ($search){
                return $q->Where('name','like','%'. $search['user_name'] .'%')
                    ;
            });
        }



        comResponse()->with( $search,'search')
            ;
        return $query;
    }

     protected function alterModelsLoaded($models, Request $request)
     {
         $models = parent::alterModelsLoaded($models, $request);
         UtilSupport::tryQuiet(function ()use (&$models){
             $models->load(['oauth_app','login_user']);
         });

         return $models;
     }

     public function modelSave(Request $request)
     {
         abort(404);
     }

    public function modelDelete(Request $request)
    {
        abort(404);
    }

    public function modelDeleteMulti(Request $request)
    {
        abort(404);
    }
}
